package com.zhuiyi.yiqingbackend.service.impl;

import com.zhuiyi.yiqingbackend.common.ErrorCode;
import com.zhuiyi.yiqingbackend.domain.User;
import com.zhuiyi.yiqingbackend.domain.request.LoginRequest;
import com.zhuiyi.yiqingbackend.exception.BusinessException;
import com.zhuiyi.yiqingbackend.mapper.UserMapper;
import com.zhuiyi.yiqingbackend.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;
    @Override
    public User login(LoginRequest loginRequest) {
        String phone = loginRequest.getPhone();
        String upassword = loginRequest.getUpassword();

        User user = userMapper.login(phone, upassword);
        if(user == null){
            throw new BusinessException(ErrorCode.NULL_ERROE, "用户名或密码错误");
        }
        return user;
    }
}
